using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using TinyERP.Framework;
using TinyERP.Core.Business;
using TinyERP.Core.DTO;
using TinyERP.Core.View.Controls;
using log4net;

namespace TinyERP.Core.View
{
    public partial class LoginForm : ComponentFactory.Krypton.Toolkit.KryptonForm
    {
        private ILog logger = LogManager.GetLogger(typeof(LoginForm));
        private IUserService UserService
        {
            get
            {
                return (IUserService)ServiceLocator.GetService("UserServiceProxy");
            }
        }
        public LoginForm()
        {
            InitializeComponent();
            UIManager.GetInstance().ApplyCurrentCultureInfo(this);
            this.DialogResult = DialogResult.Cancel;
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.Text = ModuleResourceManager.GetInstance().GetStringFromModuleResourceKey("Login, TinyERP.Core");
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            UserDTO user = UserService.Login(txtUserName.Text.Trim(), txtPassword.Text);
            if (user != null)
            {
                Session.LoginUser = user;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                lblErrorMessage.Visible = true;
            }
        }

       
    }
}